package api

import (
	"github.com/gin-gonic/gin"
	"go-iot-project/apps/entity"
	"go-iot-project/apps/repository"
	"go-iot-project/pkg/curd"
)

type DeviceApi struct {
	DeviceModel repository.DeviceModel
}

// @Summary		添加设备 值
// @Description	添加设备 值
// @Tags			device
// @Accept			json
// @Produce		json
// @Param			input	body		Device	true	"insert device"
// @Success		200		{object}	string
// @Router			/api/device/insert [post]
func (d *DeviceApi) Insert(ctx *gin.Context) {
	var data entity.Device
	err := ctx.BindJSON(&data)
	if err != nil {
		curd.Error(ctx, err)
		return
	}
	var device *entity.Device
	device, err = d.DeviceModel.FindOnyByDeviceNo(data.DeviceId)
	if err != nil {
		curd.Error(ctx, err)
		return
	}

	if device == nil {
		device = d.DeviceModel.Insert(&data)
	} else if device.Disabled {
		
	}
	curd.OK(ctx, device)
}
